package servlets;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import main.java.datatypes.HistorialVO;
import main.java.entities.Historial;
import main.java.factory.SystemFactory;
import main.java.managers.HistoriaMgr;

public class Data  extends HttpServlet {
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession objSesion = req.getSession();
		
		if(req.getServletPath().equals("/data/infoSensor")){
			String sensor = req.getParameter("sensorseleccionado");
			HistoriaMgr hm = new HistoriaMgr();
			List<Historial> lh = hm.getHistoricalForSensor(sensor);
			HistorialVO hVo = new HistorialVO(lh);
			req.setAttribute("historialvo", hVo);
			req.getRequestDispatcher("/WEB-INF/data/particular.jsp").forward(req, resp);
		}
	}
	
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession objSesion = req.getSession();
		
		if(req.getServletPath().equals("/data/general")){
			HistoriaMgr hm = new HistoriaMgr();
			List<Historial> lh = hm.getLastMeasures();
			objSesion.setAttribute("historial", lh);
			req.getRequestDispatcher("/WEB-INF/index.jsp").forward(req, resp);
		}
	}

}
